#pragma once

#ifndef _CBASEENTITY_H_
#define _CBASEENTITY_H_

#include "windows.h"
#include "structs.h"
#include "CComm.h"
#include "CBasicPacket.h"
#include "CItem.h"
#include "CWeaponItem.h"

class CStatusEffect;
class CChar;

class CBaseEntity
{
public:

	unsigned int	m_id;
	char			m_name[17];
	char			m_nameStripped[17];
	unsigned short	m_targId;
	
	unsigned short  m_objType;

	unsigned char m_jobMain, m_jobSub, m_lvlMain, m_lvlSub;

	unsigned int  m_maxHp, m_maxMp;

	unsigned short  m_modAcc;
	unsigned short  m_modAtt;

	int m_modDef;

	unsigned char m_animationAlt;
	unsigned char m_speed, m_speedAlt;
	unsigned short  m_walkCnt;

	bool m_isCasting;
	bool m_isRangedAttacking;
	unsigned short m_isUsingItem; //Slot of the item being used by the char!

	CBaseEntity * m_pTarget;

	// last attack time attack
	unsigned long long oldAttackTime;

	struct look l;

	struct location loc;

	struct stats stats;

	struct health h;

	char * getName();
	char * getStrippedName();

	int ownerId;
	bool incombat;
	unsigned short combatAction;
	bool update;

	void setObjType(unsigned short objType);
	void setZone(unsigned short zone);
	void setTargId(unsigned int targid);
	void setId(unsigned int id);

	unsigned int getId();
	unsigned short getTargId();
	int getObjectType();
	bool isCasting();
	bool isRangedAttacking();

	// Returns the base defense of a char/mob
	unsigned short getBaseDef();
	unsigned short getBaseAttack();
	unsigned short getBaseAccuracy(CBaseEntity * target);
	unsigned short getBaseEva();

	unsigned short getDef();
	unsigned short getAttack();
	unsigned short getAccuracy(CBaseEntity * target, unsigned int weaponslot = SLOT_MAIN);
	unsigned short getEva();


	unsigned short getHitRate(CBaseEntity * target);

	void missedAttackAction( CBaseEntity* target);

	position getPos();
	float getXPos();
	float getYPos();
	float getZPos();

	void setPos(struct position p);
	void setXPos(float x);
	void setYPos(float y);
	void setZPos(float z);

	unsigned short getZone();

	unsigned char getAnimation();

	void setAnimation(unsigned char anim);
	void setAltAnimation(unsigned char anim);

	unsigned short getRot();

	bool isDead();
	bool isPlayer();
	bool isNPC();
	bool isMob();

	int getMaxHp();
	int getMaxMp();

	float getMaxCRatio(CBaseEntity *target);
	float getMinCRatio(CBaseEntity *target);

	int getHp();
	short getMp();

	short getHpp();
	short getMpp();

	void disengage();
	void engage(CBaseEntity *target);

	void die();
	void takePhysicalDamage(int damage, CBaseEntity * pDamageDealer);

	void updateEnmity(CBaseEntity * schar, int vEnmity,int cEnmity);

	float getVModifier();
	float getCModifier();


	void weaponskill(unsigned short weaponskill, unsigned short damage, CBaseEntity* target);


	//Status Effects list
	std::vector<CStatusEffect*>	m_statusEffectList;

	//Status Effect functions
	void addStatusEffect(CStatusEffect * statusEffect);
	void removeStatusEffect(CStatusEffect * statusEffect);
	CStatusEffect * getStatusEffect(unsigned char type);

	unsigned short getWeaponDamage();

	CBaseEntity(void);
	~CBaseEntity(void);

	bool isFaceing(struct position p);

	struct resist r;

	int adjustDamage(CWeaponItem * weapon, int damage);

};

#endif